package cmlabs.moduloariphmetics;


/**
 * Created by IntelliJ IDEA.
 * User: jte
 * Date: 9.4.11
 * Time: 18.23
 * To change this template use File | Settings | File Templates.
 */


public class GF2Field {
    final private int irreducible[][] = {{0}, {1, 0}
            , {2, 1, 0}
            , {3, 1, 0}
            , {4, 1, 0}
            , {5, 2, 0}
            , {6, 1, 0}
            , {7, 1, 0}
            , {8, 4, 3, 1, 0}
            , {9, 1, 0}
            , {10, 3, 0}
            , {11, 2, 0}
            , {12, 3, 0}
            , {13, 4, 3, 1, 0}
            , {14, 5, 0}
            , {15, 1, 0}
            , {16, 5, 3, 1, 0}
            , {17, 3, 0}
            , {18, 3, 0}
            , {19, 5, 2, 1, 0}
            , {20, 3, 0}
            , {21, 2, 0}
            , {22, 1, 0}
            , {23, 5, 0}
            , {24, 4, 3, 1, 0}
            , {25, 3, 0}
            , {26, 4, 3, 1, 0}
            , {27, 5, 2, 1, 0}
            , {28, 1, 0}
            , {29, 2, 0}
            , {30, 1, 0}
            , {31, 3, 0}
            , {32, 7, 3, 2, 0}
            , {33, 10, 0}
            , {34, 7, 0}
            , {35, 2, 0}
            , {36, 9, 0}
            , {37, 6, 4, 1, 0}
            , {38, 6, 5, 1, 0}
            , {39, 4, 0}
            , {40, 5, 4, 3, 0}
            , {41, 3, 0}
            , {42, 7, 0}
            , {43, 6, 4, 3, 0}
            , {44, 5, 0}
            , {45, 4, 3, 1, 0}
            , {46, 1, 0}
            , {47, 5, 0}
            , {48, 5, 3, 2, 0}
            , {49, 9, 0}
            , {50, 4, 3, 2, 0}
            , {51, 6, 3, 1, 0}
            , {52, 3, 0}
            , {53, 6, 2, 1, 0}
            , {54, 9, 0}
            , {55, 7, 0}
            , {56, 7, 4, 2, 0}
            , {57, 4, 0}
            , {58, 19, 0}
            , {59, 7, 4, 2, 0}
            , {60, 1, 0}
            , {61, 5, 2, 1, 0}
            , {62, 29, 0}
            , {63, 1, 0}
            , {64, 4, 3, 1, 0}
            , {65, 18, 0}
            , {66, 3, 0}
            , {67, 5, 2, 1, 0}
            , {68, 9, 0}
            , {69, 6, 5, 2, 0}
            , {70, 5, 3, 1, 0}
            , {71, 6, 0}
            , {72, 10, 9, 3, 0}
            , {73, 25, 0}
            , {74, 35, 0}
            , {75, 6, 3, 1, 0}
            , {76, 21, 0}
            , {77, 6, 5, 2, 0}
            , {78, 6, 5, 3, 0}
            , {79, 9, 0}
            , {80, 9, 4, 2, 0}
            , {81, 4, 0}
            , {82, 8, 3, 1, 0}
            , {83, 7, 4, 2, 0}
            , {84, 5, 0}
            , {85, 8, 2, 1, 0}
            , {86, 21, 0}
            , {87, 13, 0}
            , {88, 7, 6, 2, 0}
            , {89, 38, 0}
            , {90, 27, 0}
            , {91, 8, 5, 1, 0}
            , {92, 21, 0}
            , {93, 2, 0}
            , {94, 21, 0}
            , {95, 11, 0}
            , {96, 10, 9, 6, 0}
            , {97, 6, 0}
            , {98, 11, 0}
            , {99, 6, 3, 1, 0}
            , {100, 15, 0}
            , {101, 7, 6, 1, 0}
            , {102, 29, 0}
            , {103, 9, 0}
            , {104, 4, 3, 1, 0}
            , {105, 4, 0}
            , {106, 15, 0}
            , {107, 9, 7, 4, 0}
            , {108, 17, 0}
            , {109, 5, 4, 2, 0}
            , {110, 33, 0}
            , {111, 10, 0}
            , {112, 5, 4, 3, 0}
            , {113, 9, 0}
            , {114, 5, 3, 2, 0}
            , {115, 8, 7, 5, 0}
            , {116, 4, 2, 1, 0}
            , {117, 5, 2, 1, 0}
            , {118, 33, 0}
            , {119, 8, 0}
            , {120, 4, 3, 1, 0}
            , {121, 18, 0}
            , {122, 6, 2, 1, 0}
            , {123, 2, 0}
            , {124, 19, 0}
            , {125, 7, 6, 5, 0}
            , {126, 21, 0}
            , {127, 1, 0}
            , {128, 7, 2, 1, 0}
            , {129, 5, 0}
            , {130, 3, 0}
            , {131, 8, 3, 2, 0}
            , {132, 17, 0}
            , {133, 9, 8, 2, 0}
            , {134, 57, 0}
            , {135, 11, 0}
            , {136, 5, 3, 2, 0}
            , {137, 21, 0}
            , {138, 8, 7, 1, 0}
            , {139, 8, 5, 3, 0}
            , {140, 15, 0}
            , {141, 10, 4, 1, 0}
            , {142, 21, 0}
            , {143, 5, 3, 2, 0}
            , {144, 7, 4, 2, 0}
            , {145, 52, 0}
            , {146, 71, 0}
            , {147, 14, 0}
            , {148, 27, 0}
            , {149, 10, 9, 7, 0}
            , {150, 53, 0}
            , {151, 3, 0}
            , {152, 6, 3, 2, 0}
            , {153, 1, 0}
            , {154, 15, 0}
            , {155, 62, 0}
            , {156, 9, 0}
            , {157, 6, 5, 2, 0}
            , {158, 8, 6, 5, 0}
            , {159, 31, 0}
            , {160, 5, 3, 2, 0}
            , {161, 18, 0}
            , {162, 27, 0}
            , {163, 7, 6, 3, 0}
            , {164, 10, 8, 7, 0}
            , {165, 9, 8, 3, 0}
            , {166, 37, 0}
            , {167, 6, 0}
            , {168, 15, 3, 2, 0}
            , {169, 34, 0}
            , {170, 11, 0}
            , {171, 6, 5, 2, 0}
            , {172, 1, 0}
            , {173, 8, 5, 2, 0}
            , {174, 13, 0}
            , {175, 6, 0}
            , {176, 11, 3, 2, 0}
            , {177, 8, 0}
            , {178, 31, 0}
            , {179, 4, 2, 1, 0}
            , {180, 3, 0}
            , {181, 7, 6, 1, 0}
            , {182, 81, 0}
            , {183, 56, 0}
            , {184, 9, 8, 7, 0}
            , {185, 24, 0}
            , {186, 11, 0}
            , {187, 7, 6, 5, 0}
            , {188, 6, 5, 2, 0}
            , {189, 6, 5, 2, 0}
            , {190, 8, 7, 6, 0}
            , {191, 9, 0}
            , {192, 7, 2, 1, 0}
            , {193, 15, 0}
            , {194, 87, 0}
            , {195, 8, 3, 2, 0}
            , {196, 3, 0}
            , {197, 9, 4, 2, 0}
            , {198, 9, 0}
            , {199, 34, 0}
            , {200, 5, 3, 2, 0}
            , {201, 14, 0}
            , {202, 55, 0}
            , {203, 8, 7, 1, 0}
            , {204, 27, 0}
            , {205, 9, 5, 2, 0}
            , {206, 10, 9, 5, 0}
            , {207, 43, 0}
            , {208, 9, 3, 1, 0}
            , {209, 6, 0}
            , {210, 7, 0}
            , {211, 11, 10, 8, 0}
            , {212, 105, 0}
            , {213, 6, 5, 2, 0}
            , {214, 73, 0}
            , {215, 23, 0}
            , {216, 7, 3, 1, 0}
            , {217, 45, 0}
            , {218, 11, 0}
            , {219, 8, 4, 1, 0}
            , {220, 7, 0}
            , {221, 8, 6, 2, 0}
            , {222, 5, 4, 2, 0}
            , {223, 33, 0}
            , {224, 9, 8, 3, 0}
            , {225, 32, 0}
            , {226, 10, 7, 3, 0}
            , {227, 10, 9, 4, 0}
            , {228, 113, 0}
            , {229, 10, 4, 1, 0}
            , {230, 8, 7, 6, 0}
            , {231, 26, 0}
            , {232, 9, 4, 2, 0}
            , {233, 74, 0}
            , {234, 31, 0}
            , {235, 9, 6, 1, 0}
            , {236, 5, 0}
            , {237, 7, 4, 1, 0}
            , {238, 73, 0}
            , {239, 36, 0}
            , {240, 8, 5, 3, 0}
            , {241, 70, 0}
            , {242, 95, 0}
            , {243, 8, 5, 1, 0}
            , {244, 111, 0}
            , {245, 6, 4, 1, 0}
            , {246, 11, 2, 1, 0}
            , {247, 82, 0}
            , {248, 15, 14, 10, 0}
            , {249, 35, 0}
            , {250, 103, 0}
            , {251, 7, 4, 2, 0}
            , {252, 15, 0}
            , {253, 46, 0}
            , {254, 7, 2, 1, 0}
            , {255, 52, 0}
            , {256, 10, 5, 2, 0}
            , {257, 12, 0}
            , {258, 71, 0}
            , {259, 10, 6, 2, 0}
            , {260, 15, 0}
            , {261, 7, 6, 4, 0}
            , {262, 9, 8, 4, 0}
            , {263, 93, 0}
            , {264, 9, 6, 2, 0}
            , {265, 42, 0}
            , {266, 47, 0}
            , {267, 8, 6, 3, 0}
            , {268, 25, 0}
            , {269, 7, 6, 1, 0}
            , {270, 53, 0}
            , {271, 58, 0}
            , {272, 9, 3, 2, 0}
            , {273, 23, 0}
            , {274, 67, 0}
            , {275, 11, 10, 9, 0}
            , {276, 63, 0}
            , {277, 12, 6, 3, 0}
            , {278, 5, 0}
            , {279, 5, 0}
            , {280, 9, 5, 2, 0}
            , {281, 93, 0}
            , {282, 35, 0}
            , {283, 12, 7, 5, 0}
            , {284, 53, 0}
            , {285, 10, 7, 5, 0}
            , {286, 69, 0}
            , {287, 71, 0}
            , {288, 11, 10, 1, 0}
            , {289, 21, 0}
            , {290, 5, 3, 2, 0}
            , {291, 12, 11, 5, 0}
            , {292, 37, 0}
            , {293, 11, 6, 1, 0}
            , {294, 33, 0}
            , {295, 48, 0}
            , {296, 7, 3, 2, 0}
            , {297, 5, 0}
            , {298, 11, 8, 4, 0}
            , {299, 11, 6, 4, 0}
            , {300, 5, 0}
            , {301, 9, 5, 2, 0}
            , {302, 41, 0}
            , {303, 1, 0}
            , {304, 11, 2, 1, 0}
            , {305, 102, 0}
            , {306, 7, 3, 1, 0}
            , {307, 8, 4, 2, 0}
            , {308, 15, 0}
            , {309, 10, 6, 4, 0}
            , {310, 93, 0}
            , {311, 7, 5, 3, 0}
            , {312, 9, 7, 4, 0}
            , {313, 79, 0}
            , {314, 15, 0}
            , {315, 10, 9, 1, 0}
            , {316, 63, 0}
            , {317, 7, 4, 2, 0}
            , {318, 45, 0}
            , {319, 36, 0}
            , {320, 4, 3, 1, 0}
            , {321, 31, 0}
            , {322, 67, 0}
            , {323, 10, 3, 1, 0}
            , {324, 51, 0}
            , {325, 10, 5, 2, 0}
            , {326, 10, 3, 1, 0}
            , {327, 34, 0}
            , {328, 8, 3, 1, 0}
            , {329, 50, 0}
            , {330, 99, 0}
            , {331, 10, 6, 2, 0}
            , {332, 89, 0}
            , {333, 2, 0}
            , {334, 5, 2, 1, 0}
            , {335, 10, 7, 2, 0}
            , {336, 7, 4, 1, 0}
            , {337, 55, 0}
            , {338, 4, 3, 1, 0}
            , {339, 16, 10, 7, 0}
            , {340, 45, 0}
            , {341, 10, 8, 6, 0}
            , {342, 125, 0}
            , {343, 75, 0}
            , {344, 7, 2, 1, 0}
            , {345, 22, 0}
            , {346, 63, 0}
            , {347, 11, 10, 3, 0}
            , {348, 103, 0}
            , {349, 6, 5, 2, 0}
            , {350, 53, 0}
            , {351, 34, 0}
            , {352, 13, 11, 6, 0}
            , {353, 69, 0}
            , {354, 99, 0}
            , {355, 6, 5, 1, 0}
            , {356, 10, 9, 7, 0}
            , {357, 11, 10, 2, 0}
            , {358, 57, 0}
            , {359, 68, 0}
            , {360, 5, 3, 2, 0}
            , {361, 7, 4, 1, 0}
            , {362, 63, 0}
            , {363, 8, 5, 3, 0}
            , {364, 9, 0}
            , {365, 9, 6, 5, 0}
            , {366, 29, 0}
            , {367, 21, 0}
            , {368, 7, 3, 2, 0}
            , {369, 91, 0}
            , {370, 139, 0}
            , {371, 8, 3, 2, 0}
            , {372, 111, 0}
            , {373, 8, 7, 2, 0}
            , {374, 8, 6, 5, 0}
            , {375, 16, 0}
            , {376, 8, 7, 5, 0}
            , {377, 41, 0}
            , {378, 43, 0}
            , {379, 10, 8, 5, 0}
            , {380, 47, 0}
            , {381, 5, 2, 1, 0}
            , {382, 81, 0}
            , {383, 90, 0}
            , {384, 12, 3, 2, 0}
            , {385, 6, 0}
            , {386, 83, 0}
            , {387, 8, 7, 1, 0}
            , {388, 159, 0}
            , {389, 10, 9, 5, 0}
            , {390, 9, 0}
            , {391, 28, 0}
            , {392, 13, 10, 6, 0}
            , {393, 7, 0}
            , {394, 135, 0}
            , {395, 11, 6, 5, 0}
            , {396, 25, 0}
            , {397, 12, 7, 6, 0}
            , {398, 7, 6, 2, 0}
            , {399, 26, 0}
            , {400, 5, 3, 2, 0}
            , {401, 152, 0}
            , {402, 171, 0}
            , {403, 9, 8, 5, 0}
            , {404, 65, 0}
            , {405, 13, 8, 2, 0}
            , {406, 141, 0}
            , {407, 71, 0}
            , {408, 5, 3, 2, 0}
            , {409, 87, 0}
            , {410, 10, 4, 3, 0}
            , {411, 12, 10, 3, 0}
            , {412, 147, 0}
            , {413, 10, 7, 6, 0}
            , {414, 13, 0}
            , {415, 102, 0}
            , {416, 9, 5, 2, 0}
            , {417, 107, 0}
            , {418, 199, 0}
            , {419, 15, 5, 4, 0}
            , {420, 7, 0}
            , {421, 5, 4, 2, 0}
            , {422, 149, 0}
            , {423, 25, 0}
            , {424, 9, 7, 2, 0}
            , {425, 12, 0}
            , {426, 63, 0}
            , {427, 11, 6, 5, 0}
            , {428, 105, 0}
            , {429, 10, 8, 7, 0}
            , {430, 14, 6, 1, 0}
            , {431, 120, 0}
            , {432, 13, 4, 3, 0}
            , {433, 33, 0}
            , {434, 12, 11, 5, 0}
            , {435, 12, 9, 5, 0}
            , {436, 165, 0}
            , {437, 6, 2, 1, 0}
            , {438, 65, 0}
            , {439, 49, 0}
            , {440, 4, 3, 1, 0}
            , {441, 7, 0}
            , {442, 7, 5, 2, 0}
            , {443, 10, 6, 1, 0}
            , {444, 81, 0}
            , {445, 7, 6, 4, 0}
            , {446, 105, 0}
            , {447, 73, 0}
            , {448, 11, 6, 4, 0}
            , {449, 134, 0}
            , {450, 47, 0}
            , {451, 16, 10, 1, 0}
            , {452, 6, 5, 4, 0}
            , {453, 15, 6, 4, 0}
            , {454, 8, 6, 1, 0}
            , {455, 38, 0}
            , {456, 18, 9, 6, 0}
            , {457, 16, 0}
            , {458, 203, 0}
            , {459, 12, 5, 2, 0}
            , {460, 19, 0}
            , {461, 7, 6, 1, 0}
            , {462, 73, 0}
            , {463, 93, 0}
            , {464, 19, 18, 13, 0}
            , {465, 31, 0}
            , {466, 14, 11, 6, 0}
            , {467, 11, 6, 1, 0}
            , {468, 27, 0}
            , {469, 9, 5, 2, 0}
            , {470, 9, 0}
            , {471, 1, 0}
            , {472, 11, 3, 2, 0}
            , {473, 200, 0}
            , {474, 191, 0}
            , {475, 9, 8, 4, 0}
            , {476, 9, 0}
            , {477, 16, 15, 7, 0}
            , {478, 121, 0}
            , {479, 104, 0}
            , {480, 15, 9, 6, 0}};
    private int n;
    private Polynomial generator;

    public GF2Field(int n) {
        if (n < 1){
            throw new IllegalArgumentException();
        }
        this.n = n;
        this.generator = new Polynomial(irreducible[n], this);
    }

    public Polynomial getGenerator() {
        return this.generator;
    }

    public int getSize() {
        return this.n;
    }
}
